package com.empirisoftware.test;
import java.util.List;

import org.junit.runners.BlockJUnit4ClassRunner;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;

public class GuiceTestRunner extends BlockJUnit4ClassRunner
{
  private final Injector injector;

  public GuiceTestRunner(final Class<?> classToRun, Module... modules) throws org.junit.runners.model.InitializationError
  {
    super(classToRun);
    this.injector = Guice.createInjector(modules);
  }

  @Override
  public Object createTest()
  {
    return injector.getInstance(getTestClass().getJavaClass());
  }

  @Override
  protected void validateZeroArgConstructor(List<Throwable> errors)
  {
    // Guice can inject constructors with parameters so we don't want this method to trigger an error
  }

  protected Injector getInjector()
  {
    return injector;
  }
}